#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

void Test1()
{
    int arr[10000] = {0,1,2};
    for(int i = 3;i<=10000;i++){
        arr[i] = arr[i-1] + arr[i-2];
        arr[i] %= 10000;
    }
    int n;
    while(cin>>n){
        for(int i = 0;i<n;i++)
        {
            int num;
            cin >> num;
            printf("%04d",arr[num]);
        }
        printf("\n");
    }
}

void Test2()
{
    string s;
    while(cin>>s){
        int n = 0;
        for(char i : s){
            n += i-'0';
        }

        int sum = 0;
        while(n){
            sum += n%10;
            n = n/10;
            if(n == 0 && sum/10 != 0){
                n = sum;
                sum = 0;
            }
        }
        cout<<sum<<endl;
    }
}


int main(){
    Test2();
    return 0;
}